//
//  main.m
//  3NSString
//
//  Created by zhengwei on 2/3/16.
//  Copyright © 2016 zhengwei. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        /*
//       1 字符串的初始化
        NSString *str1 = [[NSString alloc]init];
        NSString *str2 = @"abc";
        NSLog(@"str1 = %@ \nstr = %@",str1,str2);
//       2 基础数据类型－》字符串:参数1:表明参数2的数据类型 参数2:内容
        NSString *str3 = [NSString stringWithFormat:@"%d",1];
        NSString *str4 = [NSString stringWithFormat:@"%f",1.5];
        NSLog(@"str3=%@ str4=%@",str3,str4);
//       3 字符串－》基础数据类型
        
        NSString *str3 = [NSString stringWithFormat:@"%d",1];
        NSString *str4 = [NSString stringWithFormat:@"%f",1.5];
        int a = str3.intValue;
        float b = str4.floatValue;
        NSLog(@"a=%d b=%f",a,b);
         
//      4 字符串的比较
        NSString *str1 = [NSString stringWithFormat:@"%@",@"abc"];
        NSString *str2 = @"abc";
        NSString *str3 = [NSString stringWithFormat:@"%@",@"123"];
        if ([str1 isEqualToString:str2]) {//如果相等true
            NSLog(@"1 字符串相等");
        }
        if (![str1 isEqualToString:str3]) {//如果相等true
            NSLog(@"1 字符串不相等");
        }
//      很少
        if (str1 == str2) {
            NSLog(@"2 字符串相等");
        }else{
            NSLog(@"2 字符串不相等");
        }
         
//      5 字符串的大小写转化
        NSString *str1 = @"abCDefg";
        NSLog(@"%@",[str1 lowercaseString]);// 全部转化为小写
        NSLog(@"%@",[str1 uppercaseString]);// 全部转化为大写
        NSLog(@"%@",[str1 capitalizedString]);// 首字母大写
         
//      6 NSString NSArray
//      7 字符串的内容索引    012
        NSString *str1 = @"abcdefg";
        NSString *str2 = @"cde";
        NSRange rang;//结构体 字符串的长度 和位置 
        rang = [str1 rangeOfString:str2];
        NSLog(@"%lu %lu",(unsigned long)rang.length,(unsigned long)rang.location);
        */
//      8 字符串的位置索引
//        NSString *str1 = @"6001948895f3";
//
//        NSRange rang;
//        rang.length = 6;
//        rang.location = 6;
//        NSString *str2 = [str1 substringWithRange:rang];
//        NSLog(@"%@",str2);
        
        
//      9 字符串的增删改查
        NSString *str1 = @"abc";
        NSString *str2 = [str1 stringByAppendingString:@"123"];
        NSString *str3 = [str2 stringByAppendingFormat:@"%d",999];
        NSLog(@"str2=%@ str3=%@",str2,str3);
        NSString *str4 = [str3 stringByReplacingOccurrencesOfString:@"c123" withString:@"aa"];
        NSString *str5 = [str3 stringByReplacingOccurrencesOfString:@"999" withString:@""];
        NSLog(@"str4=%@ str5=%@",str4,str5);
        
        /*
//      10 可变字符串
        NSMutableString *str6 = [[NSMutableString alloc]init];
        [str6 appendString:@"abc"];
        [str6 appendString:@"123"];
        [str6 insertString:@"hhh" atIndex:3];
        [str6 appendFormat:@"%f",4.5];
        NSLog(@"str6=%@",str6);
         
//       11 字符串的内容检查
        NSString *str1  = @"http://www.imooc.com";
        if ([str1 containsString:@"imooc"]) {
            NSLog(@"包含慕课网");
        }
        if ([str1 hasPrefix:@"http"]) {
            NSLog(@"http");
        }
        if ([str1 hasSuffix:@"com"]) {
            NSLog(@"com");
        }
         */
        /*
//      12 常用技巧
        NSString *str1 = @" abc edf ";
        NSLog(@"str1=%@",str1);
        NSString *str2 = [str1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
        NSLog(@"str2=%@",str2);
        NSLog(@"%d %d",str1.length,str2.length);
         */
    }
    return 0;
}
